<?php
switch($type){
	case'add':		//添加
		
		//添加
		if($go=='insert'){
			$orders   = (int)$orders;
			$articles = (int)$articles;
			$runmode  = (int)$runmode;
			
			$names = trim($names);
			if(!$names){
				$error=1;
				basic::flash('抱歉，请输入模块名称！');
			}
			
			$links = trim($links);
			if(!$links){
				$error=1;
				basic::flash('抱歉，请输入模块链接！');
			}
			
			$ck = $db->rows("SELECT * FROM types WHERE names='$names'");
			if($ck['names']==$names){
				$error=1;
				basic::flash('抱歉，模块 '.$names.' 已经存在！');
			}
			
			
			if($error!=1){
				$db->query("INSERT INTO types (
				names,links,orders,articles,runmode
				) VALUES(
				'$names','$links','$orders','$articles','$runmode'
				)");
				
				
				basic::flash('恭喜，资料添加成功！',"sys.php?model=admin&action={$action}&type=add",3);
			}
		}
		
		
		
		$posturl   = "sys.php?model=admin&action={$action}&type=add&go=insert";
		
		$this_file = $action.'_mod';
	break;
	
	case'edit':		//编辑
		
		//更新
		if($go=='update'){
			$orders   = (int)$orders;
			$articles = (int)$articles;
			$runmode  = (int)$runmode;
			
			$names = trim($names);
			if(!$names){
				$error=1;
				basic::flash('抱歉，请输入模块名称！');
			}
			
			$links = trim($links);
			if(!$names){
				$error=1;
				basic::flash('抱歉，请输入模块名称！');
			}
			
			if($error!=1){
				$db->query("UPDATE types SET names='$names',links='$links',orders='$orders',articles='$articles',runmode='$runmode' WHERE tid='$id'");
				
				basic::flash('恭喜，资料修改成功！',"sys.php?model=admin&action={$action}&type=edit&id=".$id,3);
			}
		}
		
		
		$mod = $db->rows("SELECT * FROM types WHERE tid='$id'");
		
		
		$posturl   = "sys.php?model=admin&action={$action}&id={$id}&type=edit&go=update";
		
		
		//文章状态
		$ascheck   = ($mod['articles']==1)?'checked':'';
		
		//隐藏选项
		$rmcheck   = ($mod['runmode']==1)?'checked':'';
		
		$this_file = $action.'_mod';
	break;
	
	case'del':		//删除
		$db->query("DELETE FROM types WHERE tid='$id'");
		
		basic::flash('恭喜，资料删除成功！',"sys.php?model=admin&action={$action}",3);
	break;
	
	default:
		
		
		$info = $db->limit("SELECT * FROM types ORDER BY orders ASC,tid ASC",$page,15);
		$pager = $info['info'];
		$data_list = $info['query'];
		$pages = multi($pager['nums'],$pager['limit'],$pager['nowpage'],$pager['pages']);
		
		$this_file = $action;
}



Basic :: setModelFile('head');
Basic :: setModelFile($this_file);
Basic :: setModelFile('bottom');
$tpl->p($this_file);
?>